/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import entity.MemberCustomer;
import entity.UserLogin;
import entity.UserLoginFacadeLocal;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author SONY
 */
@Stateless
public class UserLoginService implements UserLoginServiceLocal {
    
    @EJB UserLoginFacadeLocal userLoginFacadeLocal;

    @Override
    public UserLogin checkLogin(String login_email, String login_password) {
        try {
            UserLogin user = userLoginFacadeLocal.find(login_email);
            if(user != null && user.getPassword().equals(login_password)) {
                return user;
            }
        } catch(Exception e) {
            System.err.println(e);
        }
        return null;
    }

    @Override
    public boolean checkEmail(String email) {
        try {
            UserLogin user = userLoginFacadeLocal.find(email);
            if(user != null) {
                return true;
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return false;
    }

    @Override
    public UserLogin getUserLoginDetails_byMemberID(int memberid) {
        UserLogin user = new UserLogin();
        try {
            List<UserLogin> lstUserLogins = userLoginFacadeLocal.findAll();
            for(int i = 0; i < lstUserLogins.size(); i++) {
                MemberCustomer member = lstUserLogins.get(i).getMemberID();
                if(member == null) {
                    continue;
                }else if(member.getMemberID() == memberid) {
                    user = lstUserLogins.get(i);
                    break;
                }
            }          
        } catch (Exception e) {
            System.err.println(e);
        }
        return user;
    }

}
